package com.example.musicaiap.data.database

import androidx.room.Entity
import androidx.room.PrimaryKey
import com.example.musicaiap.domain.model.Song

/**
 * 歌曲数据库实体
 * 用于Room数据库存储歌曲信息
 */
@Entity(tableName = "songs")
data class SongEntity(
    @PrimaryKey
    val id: String,
    val title: String,
    val artist: String,
    val album: String,
    val duration: Long, // 毫秒
    val coverUrl: String,
    val url: String,
    val lyricUrl: String?,
    val isVip: Boolean,
    val isLocal: Boolean, // 标识是否为本地歌曲
    val lastUpdated: Long = System.currentTimeMillis() // 最后更新时间戳
) {
    /**
     * 转换为领域模型
     */
    fun toDomainModel(): Song {
        return Song(
            id = id,
            title = title,
            artist = artist,
            album = album,
            duration = duration,
            coverUrl = coverUrl,
            url = url,
            lyricUrl = lyricUrl,
            isVip = isVip
        )
    }

    companion object {
        /**
         * 从领域模型创建数据库实体
         */
        fun fromDomainModel(song: Song, isLocal: Boolean = false): SongEntity {
            return SongEntity(
                id = song.id,
                title = song.title,
                artist = song.artist,
                album = song.album,
                duration = song.duration,
                coverUrl = song.coverUrl,
                url = song.url,
                lyricUrl = song.lyricUrl,
                isVip = song.isVip,
                isLocal = isLocal
            )
        }
    }
} 